<?php
	echo "init db";
	function create_database($host,$user,$pass,$dbname)
	{
		$conn = mysql_connect($host,$user,$pass);
		if(! $conn)
		{
			return FALSE;
		}
		$db = mysql_select_db($dbname,$conn);
		if(! $db)
		{
			return FALSE;
		}
		$res = TRUE;
		
		//users table
		$res = $res && @mysql_query("
			CREATE TABLE IF NOT EXISTS `Users` (
			`id` bigint(10) unsigned NOT NULL auto_increment,
			`username` varchar(100) collate utf8_unicode_ci NOT NULL,
			`nickname` varchar(50) collate utf8_unicode_ci NOT NULL,
			`password` varchar(100) collate utf8_unicode_ci NOT NULL,
			`email` varchar(100) collate utf8_unicode_ci NOT NULL,
			`avatar` varchar(100) collate utf8_unicode_ci NOT NULL,
			`city` varchar(150) collate utf8_unicode_ci NOT NULL,
			`about_me` varchar(80) collate utf8_unicode_ci NOT NULL,
			`reg_date` date NOT NULL,
			`reg_ip` bigint(10) NOT NULL,
			`lastlogin_date` date NOT NULL,
			`lastlogin_ip` bigint(10) NOT NULL,
			`is_spammer` tinyint(1) unsigned NOT NULL,
			`lastclick_date` int(10) unsigned NOT NULL,
			`lastpost_date` int(10) unsigned NOT NULL,
			`lastemail_date` int(10) unsigned NOT NULL,
			PRIMARY KEY (`id`),
			UNIQUE KEY `username` (`username`),
			KEY `avatar` (`avatar`),
			KEY `is_spammer` (`is_spammer`)
			)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2;
		");
		
		//logged in users
		/*$res = $res && @mysql_query("
			CREATE TABLE LoggedInUsers
			{
				`session_id` varchar(255),
				`user_id` bigint(10) NOT NULL,
				last_access datetime,
				PRIMARY KEY(`session_id`),
				FOREIGN KEY(`user_id`) REFERENCES Users(`id`),
			}ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		");*/
		
		
		//follow table
		$res = $res && @mysql_query("
			CREATE TABLE IF NOT EXISTS `Follows` (
			`id` bigint(10) unsigned NOT NULL auto_increment,
			`who` bigint(10) unsigned NOT NULL,
			`whom` bigint(10) unsigned NOT NULL,
			`gen_data` date NOT NULL,
			PRIMARY KEY (`id`),
			KEY `who` (`who`),
			KEY `whom` (`whom`)
			)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		");
		
		//action table
		/*$res = $res && @mysql_query("
			CREATE TABLE IF NOT EXISTS `Actions` (
			`id` bigint(10) unsigned NOT NULL auto_increment,
			`user_id` bigint(10) unsigned NOT NULL,
			`submit_date` date NOT NULL,
			`content` varchar(300) collate utf8_unicode_ci NOT NULL, 
			
			PRIMARY KEY (`id`),
			FOREIGN KEY (`user_id`) REFERENCES users(`id`),
			)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		");*/
		
		//action action_reply
		/*$res = $res && @mysql_query("
			CREATE TABLE IF NOT EXISTS `Action_replys` (
				`id` bigint(10) unsigned NOT NULL auto_increment,
			)
		");*/
		
		//problem table
		/*$res = $res && @mysql_query("
			CREATE TABLE IF NOT EXISTS `Problems` (
			`id` int(10) unsigned NOT NULL auto_increment,
			``
			)
		");*/
		
		return $res;
	}
	require_once('./include/conf_main.php');
	if(create_database(DB_HOST, DB_ADMIN_USER, DB_ADMIN_PASS, DB_NAME))
	{
		echo "ok";
	}
	else
	{
		echo "bu ok";
	}
	
?>